<?php
namespace app\index\controller;

class Search extends Base{
	function _initialize($is_user_login = false){
		parent::_initialize($is_user_login);
		$this->add_step('搜索');
	}
	public function index(){

		return $this->view();
	}
	// 问答
	public function question(){
		$keyword = $this->_get('keyword', '对不起，关键字不能为空！');

		$where['title|content'] = array('like', '%' . $keyword . '%');
		$where['is_delete']     = 0;
		$where['status']        = 1;
		$order = 'ask_id desc';
		$list  = model('Ask')->where($where)->order($order)->paginate(10, false, ['query' => ['keyword' => $keyword]]);

		$this->assign('list', $list);
		$this->assign('page', $list->render());
		$this->assign('module_name', 'Question');
		$this->assign('field_key', 'ask_id');

		return $this->view('index');
	}
	// 文章搜索
	public function article(){
		$keyword = $this->_get('keyword', '对不起，关键字不能为空！');

		$where['title|description'] = array('like', '%' . $keyword . '%');
		$where['is_delete']     = 0;
		$where['status']        = 1;
		$order = 'article_id desc';
		$list  = model('Article')->where($where)->order($order)->paginate(10, false, ['query' => ['keyword' => $keyword]]);

		$this->assign('list', $list);
		$this->assign('page', $list->render());
		$this->assign('module_name', 'Article');
		$this->assign('field_key', 'article_id');

		return $this->view('index');
	}
	public function user(){
		$keyword = $this->_get('keyword', '对不起，关键字不能为空！');

		$where['realname|nickname'] = array('like', '%' . $keyword . '%');
		$where['status']        = 1;
		$order = 'user_id desc';
		$list  = model('User')->where($where)->order($order)->paginate(10, false, ['query' => ['keyword' => $keyword]]);

		$this->assign('list', $list);
		$this->assign('page', $list->render());
		$this->assign('module_name', 'People');
		$this->assign('field_key', 'user_id');
		return $this->view();
	}
}